package com.example.sys.speciality.service;

import com.example.core.mapping.Mapping;
import com.example.core.service.BaseTreeServiceImpl;
import com.example.sys.attachment.service.SysAttachmentService;
import com.example.sys.speciality.dao.SysSpecialityCategoryDao;
import com.example.sys.speciality.mapping.SysSpecialityCategoryMapping;
import com.example.sys.speciality.po.SysSpecialityCategory;
import com.example.sys.speciality.vo.SysSpecialityCategoryVo;
import org.apache.commons.io.IOUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

@Service
public class SysSpecialityCategoryServiceImpl extends BaseTreeServiceImpl<SysSpecialityCategoryDao, SysSpecialityCategory, SysSpecialityCategoryVo> implements SysSpecialityCategoryService {

    @Resource
    private SysAttachmentService sysAttachmentService;

    @Override
    public Class<? extends Mapping> getMappingClass() {
        return SysSpecialityCategoryMapping.class;
    }

    @Override
    public byte[] download() throws Exception {
        InputStream inputStream = getClass().getResourceAsStream("/templates/SysSpecialityCategory.xlsx");
        return IOUtils.toByteArray(inputStream);
    }

    @Override
    public void importData(String fileId) throws Exception {

    }

    @Override
    public SysSpecialityCategory getSysSpecialityCategoryByName(String name) throws Exception {
        return getBaseMapper().findByName(name);
    }

    @Cacheable(cacheNames = TREECACHE, key = "#root.targetClass.getName()")
    @Override
    public List<SysSpecialityCategory> findTreeList(HttpServletRequest request, HttpServletResponse response) {
        return super.findTreeList(request, response);
    }
}
